var mysql = require('mysql');

//创建一个connection
var connection = mysql.createConnection({
	host : 'localhost',
	user : 'root',
	password :'root',
	port : '3306',
});
connection.connect(function(err){
	if (err) {
		console.log('[query] - :' +err);
		return;
	}

	console.log("[connection connect] succeed!");
});

//执行sql语句
connection.query('SELECT 1 + 1 AS solution',function(err,rows,fields){
	if (err) {
		console.log('[query] - '+err);
		return ;
	}
	console.log('the solution is:',rows[0].solution);
});

//关闭connection
connection.end(function(err){
	if (err) {
		return;
	}
	console.log('[connection end] succeed!');
});